<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>向上级反馈意见建议</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../layui/css/layui.css" media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
    <link rel="stylesheet" href="../../layui/font/iconfont.eot">
    <script src="../../js/jquery-3.4.1.js"></script>
    <script src="../../mock/mock/mock-min.js"></script>
    <script src="../../js/jquery-3.4.1.js"></script>
    <script src="../../mock/mock1.js"></script>
    <style>
        .chaxun {
            display: inline;
            width: 90%;
            margin-right: 20px;
        }
        
        .dignbuanniu {
            margin: 15px 0;
        }
        
        .dingbuyihang {
            padding: 0px 10px;
            width: 90%;
        }
        /*水平竖直居中  */
        
        .juzhong {
            margin-top: 30px;
            display: flex;
            justify-content: center;
            align-items: center;
        }
        
        .xingzhengcunxinxitianjia {
            width: 60%;
        }
        
        .hanggao {
            margin: 40px 0px;
        }
        
        .xiangqingtitle {
            color: #999;
        }
        
        .xiangqingcontent {
            text-align: center;
            width: 50%;
        }
        
        .xiangqingjianjie {
            width: auto;
            text-align: left;
            text-indent: 40px;
            padding: 9px 40px;
        }
    </style>
</head>

<body>
    <div style="padding: 20px; background-color: #f2f2f2">
        <div class="layui-card layui-col-space15" style="padding: 20px; background-color: #fff">
            <div class="layui-card-body">
                <form class="layui-form" action="" lay-filter="saixuan">
                    <div class="layui-row">

                        <div class="layui-col-xs1 layui-col-sm1 layui-col-md1 dignbuanniu">

                        </div>

                        <div class="layui-col-xs1 layui-col-sm1 layui-col-md1 dignbuanniu">

                        </div>

                        <div class="layui-col-xs3 layui-col-sm3 layui-col-md3 dignbuanniu"></div>

                        <div class="layui-col-xs2 layui-col-sm2 layui-col-md2 dignbuanniu">
                            <label class="layui-form-label dingbuyihang">
                                <select id="zhen1" name="townid" lay-verify="required" name="townId" lay-filter="zhen1">
                                    <option value="">地区筛选(镇/街道)</option>
                                </select>
                            </label>
                        </div>
                        <div class="layui-col-xs2 layui-col-sm2 layui-col-md2 dignbuanniu">

                            <label class="layui-form-label dingbuyihang">
                        <select name="villageId" lay-verify="required" id="cun1" name="villageId">
                            <option value="">地区筛选(村)</option>
                        </select>
                            </label>
                        </div>
                        <div class="layui-col-xs2 layui-col-sm2 layui-col-md2 dignbuanniu">
                            <input type="text" name="keyWords" required lay-verify="required" placeholder="查询内容或字段" autocomplete="off" class="layui-input chaxun">
                        </div>
                        <div class="layui-col-xs1 layui-col-sm1 layui-col-md1 dignbuanniu">
                            <button type="button" class="layui-btn" onclick="chaxun()">
                                <i class="layui-icon layui-icon-search"></i>&nbsp;&nbsp;查询
                              </button>
                        </div>

                    </div>
                </form>
                <!-- 底部表格 -->
                <table class="layui-hide" id="test" lay-filter="test"></table>
            </div>
        </div>
    </div>

    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="cehui">撤回向上反馈意见</a>
    </script>


    <script src="../../layui/layui.js" charset="utf-8"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->

    <script>
        var townName = new Array();
        var villageName = new Array();
        var currentTownId = "";
        var currentVillageId = "";
        var option
        var table
        layui.use(['table', 'form'], function() {
            table = layui.table;
            form = layui.form;

            option = {
                elem: '#test',
                url: url + "general/feedback/upfeedbacklist",
                toolbar: '#toolbarDemo', //开启头部工具栏，并为其绑定左侧模板
                headers: {
                    token: localStorage.getItem('token')
                },
                limits: [10, 20, 50, 100, 200, 500],
                where: {},
                size: "lg",
                defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                    title: '提示',
                    layEvent: 'LAYTABLE_TIPS',
                    icon: 'layui-icon-tips'
                }],
                page: {
                    curr: 1 //重新从第 1 页开始
                },
                parseData: function(res) {
                    if (res.data !== null) {
                        //res 即为原始返回的数据
                        return {
                            code: 0, //解析接口状态
                            msg: res.msg, //解析提示文本
                            // data: setdata(res), //解析数据列表
                            count: res.data.count, //解析数据长度

                            data: setdata(res.data.upfeedbacklist), //解析数据列表
                        };
                    } else {
                        //res 即为原始返回的数据
                        return {
                            code: 0, //解析接口状态
                            msg: res.msg, //解析提示文本
                            data: "", //解析数据列表
                            count: 0, //解析数据长度
                            // data: setdata(res.data.ntreatedlist), //解析数据列表
                        };
                    }

                },
                title: '用户数据表',
                cols: [
                    [{
                        type: 'checkbox',
                    }, {
                        type: "numbers",
                        title: '#',
                    }, {
                        field: 'townname',
                        title: '所属街道',
                        align: "center"
                    }, {
                        field: 'villagename',
                        title: '所属村',
                        align: "center"
                    }, {
                        field: 'title',
                        title: '反馈标题',
                        align: "center"

                    }, {
                        field: 'content',
                        title: '反馈内容',
                        align: "center"
                    }, {
                        fixed: 'right',
                        title: '操作',
                        toolbar: '#barDemo',
                        align: "center"
                    }]
                ],
                page: true
            }
            tableIns = table.render(option);

            //添加筛选条件
            // 镇生成
            towns.forEach(item => {
                    // console.log($('#zhen1')[0].innerHTML)
                    $('#zhen1')[0].innerHTML += ` <option value="` + item.id + `">` + item.name + `</option>`
                })
                // 村生成
            form.on('select(zhen1)', function(data) {
                $('#cun1').empty()
                $('#cun1')[0].innerHTML += ` <option value="">地区筛选(村)</option>`
                villages.forEach(item => {
                    if (item.townId == data.value) {
                        $('#cun1')[0].innerHTML += ` <option value="` + item.id + `">` + item.name + `</option>`
                    }
                })
                form.render('select', "saixuan")
            });
            form.render('select', "saixuan")
                //头工具栏事件
                // table.on('toolbar(test)', function(obj) {
                //     var checkStatus = table.checkStatus(obj.config.id);
                //     switch (obj.event) {
                //         case 'getCheckData':
                //             var data = checkStatus.data;
                //             layer.alert(JSON.stringify(data));
                //             break;
                //         case 'getCheckLength':
                //             var data = checkStatus.data;
                //             layer.msg('选中了：' + data.length + ' 个');
                //             break;
                //         case 'isAll':
                //             layer.msg(checkStatus.isAll ? '全选' : '未全选');
                //             break;

            //             //自定义头工具栏右侧图标 - 提示
            //         case 'LAYTABLE_TIPS':
            //             layer.alert('这是工具栏右侧自定义的一个图标按钮');
            //             break;
            //     };
            // });


            //监听行工具事件
            table.on('tool(test)', function(obj) {
                console.log(obj)
                    //console.log(obj)
                if (obj.event === 'cehui') {
                    layer.open({
                        type: 1,
                        title: '删除',
                        offset: "auto",
                        content: `<div style="font-size: 14px; color: #606266;line-height: 100px;height: 100px;text-align: center;">确认要撤回当前反馈吗!</div>`,
                        area: ["350px", "200px"],
                        btn: ['确定', '取消', ], //可以无限个按钮
                        btn1: function() {
                            var data = {};
                            data.id = obj.data.id
                            console.log(data)
                            $.ajax({
                                url: url + "general/feedback/downfeedback",
                                method: "post",
                                data: data,
                                success: function(data) {
                                    if (data.code === 200) {
                                        console.log(data);
                                        table.reload("test", option);
                                        layer.msg('撤回成功!')
                                    } else {
                                        layer.msg('撤回失败!')
                                    }
                                },
                                error: function(err) {
                                    layer.msg('撤回败!')
                                },
                            });
                            layer.closeAll();
                        },
                        btn2: function() {
                            layer.msg('已取消操作')
                        }
                    })
                }
            });
        });


        var url00;
        // 重置表单数据--开始
        function getForm(data, num) {
            console.log(data);
            if (num == 0) { // 镇
                url00 = url + "general/feedback/getfeedbackbyid?townId=" + data;
            } else if (num == 1) { // 村
                url00 = url + "general/feedback/getfeedbackbyid?townId=" + currentTownId + "&villageId=" + data;
            } else if (num == 2) { // 搜索
                // url00 = url + "general/feedback/getfeedbackbyid?townId=" + data;
            }
            option = {
                elem: '#test',
                url: url00,
                toolbar: '#toolbarDemo', //开启头部工具栏，并为其绑定左侧模板
                page: true,
                request: {
                    pageName: "currrntPage", //页码的参数名称，默认：page
                    limitName: "size", //每页数据量的参数名，默认：limit
                },
                headers: {
                    token: localStorage.getItem('token')
                },
                where: {},
                defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                    title: '提示',
                    layEvent: 'LAYTABLE_TIPS',
                    icon: 'layui-icon-tips'
                }],
                parseData: function(res) {
                    //res 即为原始返回的数据

                    return {
                        code: 0, //解析接口状态
                        msg: res.msg, //解析提示文本
                        count: res.data.count, //解析数据长度
                        data: setdata(res.data.treatedlist), //解析数据列表
                    };
                },
                title: '用户数据表',
                cols: [
                    [{
                        type: 'checkbox',
                        align: "center"
                    }, {
                        type: "numbers",
                        title: '#',
                    }, {
                        field: 'townname',
                        title: '所属街道',
                        align: "center"
                    }, {
                        field: 'villagename',
                        title: '所属村',
                        align: "center"
                    }, {
                        field: 'title',
                        title: '反馈标题',
                        align: "center"

                    }, {
                        field: 'upMessage',
                        title: '反馈内容',
                        align: "center"
                    }, {
                        fixed: 'right',
                        title: '操作',
                        toolbar: '#barDemo',
                        align: "center"
                    }]
                ]
            }
            tableIns = table.render(option);
        }
        // 重置表单数据--结束

        function setdata(data) {
            console.log(data)
            if (data.data !== null) {
                data.forEach(item => {
                    item.townname = gettown(item.townId).name
                    item.villagename = getvillage(item.villageId).name
                });
            }
            return data
        }

        function chaxun() {
            var val = $('input[name="title"]').val();
            // 连接数据库
            getForm(val, 2);
            $('input[name="title"]').val("");
        }
    </script>

</body>

</html>